#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    db= QSqlDatabase ::addDatabase("QMYSQL");//加载数据库驱动
    db.setDatabaseName("mydatabase");
    db.setHostName("localhost");
    db.setUserName("root");
    db.setPassword("123456");

    if(db.open())
    {
        QMessageBox::information(this,"提示","数据库连接成功");
    }
    else
    {
        QMessageBox::information(this,"提示","数据库打开失败");
    }


}

 Widget::~Widget()
{
    delete ui;
}
